﻿using Microsoft.AspNetCore.Authentication;
using Microsoft.AspNetCore.Authentication.JwtBearer;

namespace Identity.API;

public static class StaticConfigService
{
    public static void AddIdentityServerConfig(this IServiceCollection services)
    {
        services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
            // .AddClientCredentialsConfigService()
            // .AddPasswordConfigService()
            .AddCodeConfigService()
            ;
    }
    
    
    public static void AddClientCredentialsConfigService(this AuthenticationBuilder builder)
    {
        builder.AddIdentityServerAuthentication(options =>
        {
            options.Authority = "http://localhost:5059";
            options.RequireHttpsMetadata = false;
            options.ApiName = "api1";
        });
    }
    
    public static void AddPasswordConfigService(this AuthenticationBuilder builder)
    {
        builder.AddIdentityServerAuthentication(options =>
        {
            options.Authority = "http://localhost:5059";
            options.RequireHttpsMetadata = false;
            options.ApiName = "api1";
            options.ApiSecret = "apipwd"; //对应ApiResources中的密钥
        });
    }

    public static void AddCodeConfigService(this AuthenticationBuilder builder)
    {
        builder.AddIdentityServerAuthentication(options =>
        {
            options.Authority = "http://localhost:5059";
            options.RequireHttpsMetadata = false;
            options.ApiName = "api1";
            options.ApiSecret = "apipwd"; //对应ApiResources中的密钥
        });
    }
}